home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / fileutil.zip / FILEBLOC.C < prev    next >
C/C++ Source or Header  |  1990-06-07  |  2KB  |  52 lines

  1. /* Convert file size to number of blocks on System V-like machines.
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Written by Brian L. Matthews, blm@6sceng.UUCP. */
  19.  
  20. #if defined (STBLOCKS_MISSING) && !defined(_POSIX_SOURCE)
  21. #include <sys/types.h>
  22. #include <sys/param.h>
  23.  
  24. /* Number of direct block addresses in an inode. */
  25. #define NDIR    10
  26.  
  27. /* Return the number of blocks in a file of SIZE bytes. */
  28.  
  29. long
  30. st_blocks (size)
  31.      long size;
  32. {
  33.   long datablks = (size + BSIZE - 1) / BSIZE;
  34.   long indrblks = 0;
  35.  
  36.   if (datablks > NDIR)
  37.     {
  38.       indrblks = (datablks - NDIR - 1) / NINDIR + 1;
  39.  
  40.       if (datablks > NDIR + NINDIR)
  41.     {
  42.       indrblks += (datablks - NDIR - NINDIR - 1) / (NINDIR * NINDIR) + 1;
  43.  
  44.       if (datablks > NDIR + NINDIR + NINDIR * NINDIR)
  45.         indrblks++;
  46.     }
  47.     }
  48.  
  49.   return datablks + indrblks;
  50. }
  51. #endif
  52.